package com.lineage.data.item_etcitem.add;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1MonsterInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Object;
import com.lineage.server.serverpackets.S_DoActionGFX;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.world.World;
import java.util.ArrayList;
import java.util.Iterator;

public class Purificationl_Magic_Wand extends ItemExecutor {
  public static ItemExecutor get() {
    return new Purificationl_Magic_Wand();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    if (item == null)
      return; 
    if (pc == null)
      return; 
    if (pc.getMapId() >= 4001 && pc.getMapId() <= 4050) {
      if (item.getChargeCount() == 0) {
        pc.getInventory().deleteItem(item);
        return;
      } 
      pc.sendPacketsX8((ServerBasePacket)new S_DoActionGFX(pc.getId(), 17));
      int useCount = item.getChargeCount() - 1;
      if (useCount > 0) {
        item.setChargeCount(useCount);
        pc.getInventory().updateItem(item, 128);
      } else {
        pc.getInventory().deleteItem(item);
      } 
      ArrayList<L1Object> list = World.get().getVisibleObjects((L1Object)pc, 5);
      if (list == null)
        return; 
      Iterator<L1Object> iterator = list.iterator();
      while (iterator.hasNext()) {
        L1Object object = iterator.next();
        if (object instanceof L1MonsterInstance) {
          L1MonsterInstance dota = (L1MonsterInstance)object;
          dota.broadcastPacketAll((ServerBasePacket)new S_DoActionGFX(dota.getId(), 2));
          dota.receiveDamage((L1Character)pc, 250);
        } 
      } 
      pc.sendPacketsAll((ServerBasePacket)new S_SkillSound(pc.getId(), 12256));
    } else {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("只能在尸魂塔副本使用。"));
    } 
  }
}
